using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.User;

public partial class controls_usrLoginStatus : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.UserTypeId] != null)
        {
            liLogin.Visible = false;
            btnLogout.Visible = true;
            liLoginStatus.Visible = true;
            if (Session[CE.Global.General.AgentId] == null && Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
                Convert.ToInt32(CE.Global.CEUserType.Customer))
            {
                if (Request.Url.PathAndQuery.ToLower().Contains("viewresulthistory.aspx"))
                {
                    hplSavedQuotes.Enabled = false;
                }
                else
                {
                    hplSavedQuotes.Enabled = true;
                }

                if (Request.Url.PathAndQuery.ToLower().Contains("editprofile.aspx"))
                {
                    hplEditProfile.Enabled = false;
                }
                else
                {
                    hplEditProfile.Enabled = true;
                }

                if (Request.Url.PathAndQuery.ToLower().Contains("changepassword.aspx"))
                {
                    hplChangePassword.Enabled = false;
                }
                else
                {
                    hplChangePassword.Enabled = true;
                }


                if (Session[CE.Global.General.UserEmail] != null)
                {
                    //string[] _userName = Session[CE.Global.General.UserName].ToString().Split(' ');
                    //string _strName = "";
                    //if (_userName.Length > 0)
                    //{
                    //    //for (int i = 0; i < _userName.Length; i++)
                    //    //{
                    //    //    if (i == 0 && _userName[i].Length > 15)
                    //    //    {
                    //    //        _strName = _userName[i].Substring(0, 12) + "...";
                    //    //        break;
                    //    //    }
                    //    //    else if (i == 0 && _userName[i].Length <= 15)
                    //    //    {
                    //    //        _strName += _userName[i].ToString();
                    //    //    }
                    //    //    else if (i > 0 && (_strName.Length + _userName[i].Length) <= 15)
                    //    //    {
                    //    //        _strName += " " + _userName[i];
                    //    //    }
                    //    //    else
                    //    //    {
                    //    //        break;
                    //    //    }
                    //    //}

                    //    CE.User.Profile usrprofile = new Profile();
                    //    ProfileDB usrprofiledb = new ProfileDB();

                    //    usrprofile = usrprofiledb.GetProfile(Convert.ToInt64(Session[CE.Global.General.UserId].ToString()));

                    //    string userfirstname = "";

                    //    if (usrprofile != null)
                    //    {
                    //        userfirstname = usrprofile.FirstName;
                    //    }

                    //    _strName = userfirstname;
                    //}
                    //else
                    //{
                    //    _strName = Session[CE.Global.General.UserName].ToString();
                    //}

                    lblUserName.Text = Session[CE.Global.General.UserName].ToString(); ;
                    //lblUserName.Text = Session[CE.Global.General.UserEmail].ToString();
                    lblUserName.ToolTip = Session[CE.Global.General.UserEmail].ToString();
                    
                    //liLoginStatus.Visible = true;
                    //liLoginStatus.Attributes.Add("class", "signout");
                    //hplLoginStatus.Text = "Sign Out";
                    //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";

                    //liRegister.Visible = false;
                    liChangePassword.Visible = true;

                    hplSavedQuotes.ToolTip = "View Saved Quotes";
                    liSavedQuotes.Visible = true;
                    liEditProfile.Visible = true;
                }
                else
                {
                    lblUserName.Text = "No Email";
                    //liLoginStatus.Attributes.Add("class", "signout");
                    //liLoginStatus.Visible = true;
                    //hplLoginStatus.Text = "Sign Out";
                    //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";

                    //liRegister.Visible = false;
                    liChangePassword.Visible = false;
                    hplSavedQuotes.ToolTip = "View Saved Quotes";
                    liSavedQuotes.Visible = true;
                    liEditProfile.Visible = true;
                }
            }
            else if (Session[CE.Global.General.AgentId] != null)
            {
                if (Session[CE.Global.General.ProviderCompanyId] != null)
                {

                    if (Session[CE.Global.General.ProviderCompanyId].ToString() == "29")
                    {
                        hplSavedQuotes.Text = "Liberty Insurance";
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == "30")
                    {
                        hplSavedQuotes.Text = "Etiqa Insurance";
                    }

                    liSavedQuotes.Visible = true;
                    hplSavedQuotes.ToolTip = "";
                    hplSavedQuotes.NavigateUrl = "";

                    liEditProfile.Visible = true;
                    if (Session[CE.Global.General.UserEmail] != null)
                    {
                        string[] _userName = Session[CE.Global.General.UserName].ToString().Split(' ');
                        string _strName = "";
                        if (_userName.Length > 0)
                        {
                            for (int i = 0; i < _userName.Length; i++)
                            {
                                if (i == 0 && _userName[i].Length > 15)
                                {
                                    _strName = _userName[i].Substring(0, 12) + "...";
                                    break;
                                }
                                else if (i == 0 && _userName[i].Length <= 15)
                                {
                                    _strName += _userName[i].ToString();
                                }
                                else if (i > 0 && (_strName.Length + _userName[i].Length) <= 15)
                                {
                                    _strName += " " + _userName[i];
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            _strName = Session[CE.Global.General.UserName].ToString();
                        }
                        hplEditProfile.NavigateUrl = "";
                        lblUserName.Text = _strName;
                        lblUserName.ToolTip = Session[CE.Global.General.UserName].ToString();
                    }
                    //liLoginStatus.Visible = true;
                    //liRegister.Visible = false;
                    liChangePassword.Visible = false;
                    //hplLoginStatus.Text = "Sign Out";
                    //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";
                }
            }
            else if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
                Convert.ToInt32(CE.Global.CEUserType.Provider))
            {
                if (Session[CE.Global.General.ProviderCompanyId] != null)
                {

                    if (Session[CE.Global.General.ProviderCompanyId].ToString() == "29")
                    {
                        lblUserName.Text = "UAT Site - Liberty Insurance";
                        liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "UAT Site - Liberty Insurance Home";
                        //hplSavedQuotes.NavigateUrl = "~/Provider/CarInsurance/LibertyInsuranceHome.aspx";
                        hplSavedQuotes.NavigateUrl = "~/provider/providerhome.aspx";
                        liEditProfile.Visible = false;
                        //liLoginStatus.Visible = true;
                        //liRegister.Visible = false;
                        liChangePassword.Visible = false;
                        //hplLoginStatus.Text = "Sign Out";
                        //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == "30")
                    {
                        lblUserName.Text = "UAT Site - Etiqa Insurance";
                        liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "UAT Site - Etiqa Insurance Home";
                        //hplSavedQuotes.NavigateUrl = "~/Provider/CarInsurance/LibertyInsuranceHome.aspx";
                        hplSavedQuotes.NavigateUrl = "~/provider/providerhome.aspx";
                        liEditProfile.Visible = false;
                        //liLoginStatus.Visible = true;
                        //liRegister.Visible = false;
                        liChangePassword.Visible = false;
                        //hplLoginStatus.Text = "Sign Out";
                        //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == "23")
                    {
                        lblUserName.Text = "UAT Site - HSBC Insurance";
                        liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "UAT Site - HSBC Insurance Home";
                        hplSavedQuotes.NavigateUrl = "~/provider/providerhome.aspx";
                        liEditProfile.Visible = false;
                        //liLoginStatus.Visible = true;
                        //liRegister.Visible = false;
                        liChangePassword.Visible = false;
                        //hplLoginStatus.Text = "Sign Out";
                        //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == "28")
                    {
                        lblUserName.Text = "UAT Site - MayBank";
                        liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "UAT Site - MayBank Home";
                        hplSavedQuotes.NavigateUrl = "~/provider/homerefinancing/hfhome.aspx";
                        liEditProfile.Visible = false;
                        //liLoginStatus.Visible = true;
                        //liRegister.Visible = false;
                        liChangePassword.Visible = false;
                        //hplLoginStatus.Text = "Sign Out";
                        //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == "24")
                    {
                        lblUserName.Text = "UAT Site - RSA";
                        liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "UAT Site - RSA Home";
                        hplSavedQuotes.NavigateUrl = "~/provider/providerhome.aspx";
                        liEditProfile.Visible = false;
                        //liLoginStatus.Visible = true;
                        //liRegister.Visible = false;
                        liChangePassword.Visible = false;
                        //hplLoginStatus.Text = "Sign Out";
                        //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == "34")
                    {
                        lblUserName.Text = "UAT Site - China Taiping";
                        liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "UAT Site - China Taiping Home";
                        hplSavedQuotes.NavigateUrl = "~/provider/providerhome.aspx";
                        liEditProfile.Visible = false;
                        //liLoginStatus.Visible = true;
                        //liRegister.Visible = false;
                        liChangePassword.Visible = false;
                        //hplLoginStatus.Text = "Sign Out";
                        //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == "35")
                    {
                        lblUserName.Text = "UAT Site - EQ Insurance";
                        liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "UAT Site - EQ Insurance Home";
                        hplSavedQuotes.NavigateUrl = "~/provider/providerhome.aspx";
                        liEditProfile.Visible = false;
                        //liLoginStatus.Visible = true;
                        //liRegister.Visible = false;
                        liChangePassword.Visible = false;
                        //hplLoginStatus.Text = "Sign Out";
                        //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == "38")
                    {
                        lblUserName.Text = "UAT Site - Direct Asia Insurance";
                        liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "UAT Site - Direct Asia Insurance Home";
                        hplSavedQuotes.NavigateUrl = "~/provider/providerhome.aspx";
                        liEditProfile.Visible = false;
                        //liLoginStatus.Visible = true;
                        //liRegister.Visible = false;
                        liChangePassword.Visible = false;
                        //hplLoginStatus.Text = "Sign Out";
                        //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";
                    }
                    else
                    {
                        lblUserName.Text = "UAT Site - Provider";
                        //liLoginStatus.Visible = true;
                        liChangePassword.Visible = false;
                        //hplLoginStatus.Text = "Sign Out";
                        //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";
                    }
                }
                else
                {
                    lblUserName.Text = "UAT Site - Provider";
                    //liLoginStatus.Visible = true;
                    liChangePassword.Visible = false;
                    //hplLoginStatus.Text = "Sign Out";
                    //hplLoginStatus.NavigateUrl = "~/user/logout.aspx";
                }
            }
            else
            {
                lblUserName.Text = "";
                //liLoginStatus.Attributes.Add("class", "first");
                //liLoginStatus.Visible = true;
                //hplLoginStatus.Text = "Sign In";
                liChangePassword.Visible = false;
                //hplLoginStatus.NavigateUrl = "~/car-insurance/loginandregister.aspx";

                //liRegister.Visible = true;
                btnLogout.Visible = false;
                liLoginStatus.Visible = false;
                liSavedQuotes.Visible = false;
                liEditProfile.Visible = false;
            }
        }
        else
        {
            //lblUserName.Text = "";
            //liLoginStatus.Attributes.Add("class", "first");
            //hplLoginStatus.Text = "Sign In";
            //hplLoginStatus.NavigateUrl = "~/User/loginandregister.aspx";

            //liRegister.Visible = true;
            //liSavedQuotes.Visible = false;
            //liEditProfile.Visible = false;
            //liLoginStatus.Visible = false;
            //liRegister.Visible = false;

            liLogin.Visible = true;
            divUserInfo.Visible = false;
        }
    }

    protected void btnLogout_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/user/logout.aspx");
    }
}
